<?php
namespace Modules\Core\Models;

use Phalcon\Mvc\MongoCollection;

class Log extends MongoCollection
{
    public $id;
    public $data;
    /**
     * @var
     */
    public $type;
    /**
     * @var string
     * notice 消息
     * info 警告
     * warning 错误
     * danger 致命
     */
    public $level;
    public $created;
    public $del;

    public function beforeValidationOnCreate()
    {
        $this->created = time();
        if (!$this->del) {
            $this->del = 168;
        }
    }

    public static function add($data)
    {
        $logClass = new Log();
        foreach ($data as $key => $value) {
            $logClass->{$key} = $value;
        }
        return $logClass->save();
    }
}
